package com.unity.bh3.config;

import com.unity.bh3.interceptor.UserAuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web配置类
 * 配置拦截器等Web相关设置
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private UserAuthInterceptor userAuthInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userAuthInterceptor)
                .addPathPatterns("/api/**") // 拦截所有API请求
                .excludePathPatterns(
                        "/api/user/register", // 排除用户注册接口
                        "/api/user/login",    // 排除用户登录接口
                        "/doc.html",          // 排除API文档页面
                        "/swagger-ui/**",     // 排除Swagger UI
                        "/v3/api-docs/**",    // 排除API文档接口
                        "/webjars/**",        // 排除静态资源
                        "/favicon.ico"        // 排除图标
                );
    }
}